<?php

class Arguments {
	private $_argumentMap = array(
		'Source'               => 'src',
		'Destination'          => 'dest',
		'Verbose'              => 'v',
		'Help'                 => 'h',
		'Duplicate File Name'  => 'dupname',
		'Duplicate File Hash'  => 'duphash',
		'Duplicate Audio Hash' => 'dupaudiohash',
		'Reorganize'           => 'reorg'
	);
	private $_argumentsWithValues = array(
		'src',
		'dest',
		'dupname',
		'duphash',
		'dupaudiohash',
	);

	private $_arguments = array();

	public function __construct($arguments)
	{
		$arguments = array_reverse($arguments);
		array_splice($arguments, count($arguments) - 1);

		while (count($arguments) > 0) {
			$argument = str_replace('-', '', array_pop($arguments));
			$value = true;
			if (in_array($argument, $this->_argumentsWithValues)) {
				$value = array_pop($arguments);
			}
			$this->_arguments[$argument] = $value;

		}
	}

	public function getArgumentByName($name)
	{
		return $this->_argumentMap[$name];
	}

	/**
	 * @param $argument 'Directory'
	 * @return $defaultValue when the argument was not supplied or the argument value
	 *          for arguments without values like -v, true is returned
	 */
	public function getArgumentValue($argument, $defaultValue)
	{
		if (!array_key_exists($this->_argumentMap[$argument], $this->_arguments)) {
			return $defaultValue;
		}
		return $this->_arguments[$this->_argumentMap[$argument]];
	}

	public static function printHelp()
	{
		print "\nSignWav usage:\n\n";
		print "-src Music\t\t\t\tSource Directory of music\n";
		print "-dest Music2\t\t\t\tDestination Directory of reorganized music\n";
		print "-v\t\t\t\t\tVerbose logging\n";
		print "-dupname dup-names.log\t\t\tFind Duplicate File Names\n";
		print "-duphash dup-file-hash.log\t\tFind Duplicate File Name md5 hash\n";
		print "-dupaudiohash dup-audio-hash.log\tFind Duplicate Audio only md5 hash\n";
		print "-reorg \t\t\t\t\tReorgainze -src into -dest\n";
		print "\n";
	}
}
